﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace GL_TakeEgg
{
    public enum FallerType
    {
        SHIT, EGG_BLUE, EGG_RED, EGG_PINK, EGG_GOLD,
    }

    public class Faller
    {
        #region Private Variables
        private FallerType _type;
        private Image _img;
        private int _x;
        private int _y;
        private int _height;
        private int _width;
        private int _speed;

        #endregion

        public delegate void touchBottom_Handler(object sender);
        public event touchBottom_Handler touchBottom;
        protected void TouchBottom()
        {
            if (touchBottom != null)
            {
                touchBottom(this);
            }
        }

        public delegate void touchBasket_Handler(object sender);
        public event touchBasket_Handler touchBasket;
        protected void TouchBasket()
        {
            if (touchBasket != null)
            {
                touchBasket(this);
            }
        }

        #region Properties

        public FallerType FType
        {
            set
            {
                _type = value;
            }
            get
            {
                return _type;
            }
        }

        public int X
        {
            set
            {
                _x = value;
            }
            get
            {
                return _x;
            }
        }

        public int Y
        {
            set
            {
                _y = value;
            }
            get
            {
                return _y;
            }
        }

        public int Height
        {
            set
            {
                _height = value;
            }
            get
            {
                return _height;
            }
        }

        public int Width
        {
            set
            {
                _width = value;
            }
            get
            {
                return _width;
            }
        }

        public int Speed
        {
            set
            {
                _speed = value;
            }
            get
            {
                return _speed;
            }
        }

        #endregion

        public Faller(FallerType ft)
        {
            _type = ft;
            switch (ft)
            {
                case FallerType.EGG_BLUE: _img = GL_TakeEgg.Properties.Resources.egg_blue; break;
                case FallerType.EGG_RED: _img = GL_TakeEgg.Properties.Resources.egg_red; break;
                case FallerType.EGG_PINK: _img = GL_TakeEgg.Properties.Resources.egg_pink; break;
                case FallerType.EGG_GOLD: _img = GL_TakeEgg.Properties.Resources.egg_gold; break;
                case FallerType.SHIT: _img = GL_TakeEgg.Properties.Resources.shit; break;
            }
        }

        public void DrawFaller(Graphics g)
        {
            g.DrawImage(_img,_x,_y,Width,Height);
        }

        public void DrawFaller(Graphics g, int move_x, int move_y)
        {
            _x = move_x;
            _y = move_y;
            DrawFaller(g);
        }

        public void Falling(int screenHeight, int screenWidth, int nkX, int bkY)
        {
            if (Y >= 0)
            {
                Y = Y + Speed;
                if (nkX <= X && X <= (nkX + 35) && 295 < Y && Y < 300)
                {
                    TouchBasket();
                }else if (Y >= screenHeight - Height)
                {
                    Y = -50;
                    TouchBottom();
                }
            }
        }

    }
}
